﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Utils;
using DataHelper;

namespace DAL
{
   public class EmpItemChangeDao
    {
        public bool Insert(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().InsertTable(tableName, sdList);
        }


        public bool Update(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().UpdateTable(tableName, sdList);
        }


        public bool DeleteOneInfo(string changeID)
        {

            return SQLHelper.ExecuteSqlWithTransaction("Delete from Wage_Change Where ChangeID=" + changeID);
        }
        //获取一条记录
        public DataTable GetOneInfo(string changeID)
        {
            return SQLHelper.ExecuteSqlGetDrToDt("Select * from Wage_Change Where ChangeID=" + changeID);
        }
        //职位列表SQL
        public string GetSQL(string serWord, string bTime, string eTime, string changeTypeName, string deptName)
        {
            StringBuilder strSQL = new StringBuilder("Select * From Wage_Change Where 1=1 ");
            if (!string.IsNullOrWhiteSpace(serWord) && serWord != "null")
                strSQL.Append(" And (EmpCode='" + serWord + "' Or EmpName Like '%" + serWord + "%')");
            else
            {
                if (!string.IsNullOrWhiteSpace(deptName) )
                    strSQL.Append("and DeptName='" + deptName + "'");
                if (changeTypeName != "" && changeTypeName!="0")
                    strSQL.Append(" and ChangeTypeName ='" + changeTypeName + "' ");

                if (RegexRule.IsDate(bTime))
                    strSQL.Append(" And ChangeTime>='" + bTime + "'");
                if (RegexRule.IsDate(eTime))
                    strSQL.Append(" And ChangeTime<='" + eTime + "'");
            }
            return strSQL.ToString();
        }
        //职位变动列表
        public DataTable GetLists(string serWord, string bTime, string eTime, string changeTypeName, string deptName)
        {
            DataTable dt = SQLHelper.ExecuteSqlGetDrToDt(GetSQL(serWord, bTime, eTime, changeTypeName, deptName));
            return dt;
        }
       //批量操作的
        //查询出这些人 -------批量 修改工资项的金额(指定月份转正，加薪，调职，晋升的人)
        public DataTable GetEmpList(string wageItem, string strMonth, string actionType)
        {
            SqlParameter para = new SqlParameter("@wageItem", SqlDbType.NVarChar);
            SqlParameter para1 = new SqlParameter("@strMonth", SqlDbType.Char);
            SqlParameter para2 = new SqlParameter("@actionType", SqlDbType.NVarChar);
            para.Value = wageItem; ;
            para1.Value = strMonth;
            para2.Value = actionType;
            SqlParameter[] spList = { para, para1, para2 };
            return SQLHelper.ExecutePorcedureGetDataSet("spJimGetEmpToModiWageItem", spList).Tables[0];

        }
    }
}
